import Vue from 'vue'
import VueRouter from 'vue-router'
const Shoot = () => import('../components/home/shoot/Shoot')
const UploadVideo = () => import('../components/home/uploadVideo/UploadVideo')
const UploadPhoto = () => import('../components/home/uploadPhoto/UploadPhoto')
const Personal = () => import('../components/home/personal/Personal')
const info = () => import('../components/home/personal/info')
const resetPassword = () => import('../components/home/personal/password')
const Learn = () => import('../components/home/learn/Learn.vue')
const Identity = () => import('../components/home/identity/Identity.vue')
const index = () => import('../components/index/Index.vue')
const Login = () => import('../components/login/Login')
const Register = () => import('../components/register/Register')
const Main = () => import('../components/home/main/main')
const Home = () => import('../components/home/Home')
const Course = () => import('../components/home/course/Course')

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    component: index
  },
  {
    path: '/home',
    component: Home,
    redirect: '/main',
    children: [
      {
        path: '/main',
        component: Main,
      },
      {
        path: '/identity',
        component: Identity,
        children: [{
          path: '/shoot',
          component: Shoot,
        },
        {
          path: '/uploadVideo',
          component: UploadVideo,
        },
        {
          path: '/uploadPhoto',
          component: UploadPhoto,
        },]
      },
      {
        path: '/course',
        component: Course,
      },
      {
        path: '/learn',
        component: Learn,
      },
      {
        path: '/personal',
        component: Personal,
      },
      {
        path: '/info',
        component: info,
      },
      {
        path: '/resetPassword',
        component: resetPassword,
      },

    ]
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/register',
    component: Register,
  },
]
const router = new VueRouter({
  //mode: 'history',
  routes
})

// router.beforeEach((to,from, next) => {
//   if (to.meta.requireAuth) { // 判断跳转的路由是否需要登录
//       if (window.sessionStorage.getItem('token')) { // vuex.state判断token是否存在
//         next() // 已登录
//       } else {
//         console.log("aaaaaaaaaa");
//           next({
//               path: '/login.html',
//                // 将跳转的路由path作为参数，登录成功后跳转到该路由
//           })
//       }
//   } else {
//      next()
//   }
// })

export default router
